package com.ease.access.systemmonitor.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ease.access.systemmonitor.service.DbInstaceAccessService;
import com.ease.business.systemmonitor.util.MapUtil;
import com.ease.common.vo.MapParameter;
import com.ease.model.systemmonitor.DbInstace;
import com.ease.platform.access.service.impl.AbstractJdbcTemplateAccessServiceImpl;

@Deprecated
/*
 * 请继承 AbstractParameterizedBeanJdbcTemplateAccessServiceImpl sql写在对应的文件里，参考DatabaseTable和DatabaseTable.statement.xml里
 */
public class DbInstaceAccessServiceImpl extends AbstractJdbcTemplateAccessServiceImpl implements DbInstaceAccessService {

	public List<DbInstace> findAllDbInstanceInfo(Object obj) {
		// TODO Auto-generated method stub
		String sql = "SELECT INSTANCE_NAME, VERSION, STARTUP_TIME, STATUS, PARALLEL, ARCHIVER, " + "LOGINS, SHUTDOWN_PENDING, DATABASE_STATUS, INSTANCE_ROLE, ACTIVE_STATE, BLOCKED "
				+ " from v$instance";
		MapParameter parameter = new MapParameter();
		List<Map<String, Object>> resultList = this.getJdbcTemplateDataAccessObject().find(sql, parameter);
		List<DbInstace> listDbInstace = new ArrayList<DbInstace>();
		if (listDbInstace != null)
			for (int i = 0; i < resultList.size(); i++) {
				HashMap<String, Object> map = (HashMap<String, Object>) resultList.get(i);
				DbInstace bean = new DbInstace();
				bean.setInstanceName(MapUtil.getStr(map, "INSTANCE_NAME"));
				bean.setDbVersion(MapUtil.getStr(map, "VERSION"));
				bean.setStartTime((Date) map.get("STARTUP_TIME"));
				bean.setStatus(MapUtil.getStr(map, "STATUS"));
				bean.setParallel(MapUtil.getStr(map, "PARALLEL"));
				bean.setArchiver(MapUtil.getStr(map, "ARCHIVER"));
				bean.setLogins(MapUtil.getStr(map, "LOGINS"));
				bean.setShutDownPending(MapUtil.getStr(map, "SHUTDOWN_PENDING"));
				bean.setDbStatus(MapUtil.getStr(map, "DATABASE_STATUS"));
				bean.setInstanceRole(MapUtil.getStr(map, "INSTANCE_ROLE"));
				bean.setActiveStatus(MapUtil.getStr(map, "ACTIVE_STATE"));
				bean.setBlocked(MapUtil.getStr(map, "BLOCKED"));
				listDbInstace.add(bean);
			}
		return listDbInstace;
	}

	// 查询系统时间 lag时差，弱为0表示当前时间
	public Date sysdate(long lag) {
		Date obj = this.getJdbcTemplateDataAccessObject().getJdbcTemplate().queryForObject("select sysdate + " + lag + " from dual", Date.class);
		return obj;
	}
}
